// xc_lshop/shop/pro/consignment/list.js
var actbill = require('../../model/order_bill')
var app = getApp();

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    value:"",
    isempty:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  xcloaddata: function (options, config) {
    
    var that=this;
    if(config.rebate.status==-1){
      wx.showToast({
        title: "返利团功能尚未开启",
        icon: 'error',
        duration: 2000,
        })
        setTimeout( function () {
          that.gohome()
        }, 2000)
    }else{
      if(config.rebate.consignment==-1){
        wx.showToast({
          title: "返利团寄售功能尚未开启",
          icon: 'error',
          duration: 2000,
          })
          setTimeout( function () {
            that.gohome()
          }, 2000)
      }else{
        that.getpagelist(that,1)
      }
    }
     
  },
  gohome(){
    var app =getApp();
    console.log('wx.reLaunch9999999999999')

    wx.reLaunch({url:app.globalData.configdata["basic"]["homeurl"]});
   },
  buy(e){
    var item=e.currentTarget.dataset.item

    var newmodel={flag:-1};
    newmodel['id']=item['id'];
    newmodel['proid']=item['orderinfo']['orderinfo'][0]['proid'];
    newmodel['pro_ident']=item['orderinfo']['orderinfo'][0]['pro_ident'];
    newmodel['realprice']=item['consignmentprice'];
    newmodel['activityprice']=item['consignmentprice'];
    newmodel['price']=item['orderinfo']['totalprice'];
    newmodel['orderid']=item['orderid'];
    newmodel['activityid']=item['orderinfo']['orderinfo'][0]['activityid'];
    newmodel['cid']=item['orderinfo']['orderinfo'][0]['cid'];
    newmodel['keyval']=item['orderinfo']['orderinfo'][0]['keyval'];
    newmodel['name']=item['orderinfo']['orderinfo'][0]['name'];
    newmodel['num']=item['orderinfo']['orderinfo'][0]['num'];
    newmodel['weight']=item['orderinfo']['orderinfo'][0]['weight'];
    newmodel['simg']=item['orderinfo']['orderinfo'][0]['simg'];

    
    if(item['orderinfo']['orderinfo'][0]['attrnameinfo']){
      newmodel['attrnameinfo']=item['orderinfo']['orderinfo'][0]['attrnameinfo']
    }
    app.globalData.temcart = {};
    app.globalData.temcart["data"] = [newmodel];  
    wx.navigateTo({
      url: '/' + app.globalData.xcsys.m + '/shop/paycore/payinfo?iscart=-1'
    })


  },
  onChange(e) {

    this.setData({
      value: e.detail,
    });
  },
  onClear(){
    this.setData({
      value:"",
    });
    var that=this;
    that.getpagelist(that,1)
  },
  onSearch(){
 
    var that=this;
    that.getpagelist(that,1)
  },
  getpagelist(that, rest, strwhere) {
    if (rest == 1) {
      if (!strwhere) {
        strwhere = {
          "keyval":this.data.value
        }
      }
      that.setData({
        modellist: [],
        isempty: false
      });
    }
    actbill.consignoffset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};
      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {
        if (result["obj"]["modellist"].length < 1) {
          updatemdoel["isempty"] = true
        } else if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      // that.selectComponent("#ordercomment").showmodel( updatemdoel["modellist"][0],"order")      
      wx.stopPullDownRefresh();

      that.setData(updatemdoel);
    }, function () {

    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})